package com.example.vdfandroidproject;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class ChooseModeActivity extends Activity implements OnClickListener {

	private Button mode1Button;
	private Button mode2Button;
	private Button mode3Button;
	private Button mode4Button;
	private Button mode5Button;
	private Button mode6Button;

	private long timerDurationInMillis;
	private String modeLabel;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_choose_mode);

		this.timerDurationInMillis = 0;

		this.mode1Button = (Button) this.findViewById(R.id.mode1Button);
		this.mode1Button.setOnClickListener(this);

		this.mode2Button = (Button) this.findViewById(R.id.mode2Button);
		this.mode2Button.setOnClickListener(this);

		this.mode3Button = (Button) this.findViewById(R.id.mode3Button);
		this.mode3Button.setOnClickListener(this);

		this.mode4Button = (Button) this.findViewById(R.id.mode4Button);
		this.mode4Button.setOnClickListener(this);

		this.mode5Button = (Button) this.findViewById(R.id.mode5Button);
		this.mode5Button.setOnClickListener(this);

		this.mode6Button = (Button) this.findViewById(R.id.mode6Button);
		this.mode6Button.setOnClickListener(this);

	}

	@Override
	public void onClick(View v) {
		this.timerDurationInMillis = 0;
		this.modeLabel = null;
		if (v.getId() == R.id.mode1Button) {
			this.timerDurationInMillis = 3 * 60 * 1000;
			this.modeLabel = getString(R.string.mode1);
		} else if (v.getId() == R.id.mode2Button) {
			this.timerDurationInMillis = 5 * 60 * 1000;
			this.modeLabel = getString(R.string.mode2);
		} else if (v.getId() == R.id.mode3Button) {
			this.timerDurationInMillis = 10 * 60 * 1000;
			this.modeLabel = getString(R.string.mode3);
		} else if (v.getId() == R.id.mode4Button) {
			this.timerDurationInMillis = 10 * 60 * 1000;
			this.modeLabel = getString(R.string.mode4);
		} else if (v.getId() == R.id.mode5Button) {
			this.timerDurationInMillis = 6 * 60 * 1000;
			this.modeLabel = getString(R.string.mode5);
		} else if (v.getId() == R.id.mode6Button) {
			this.timerDurationInMillis = 8 * 60 * 1000;
			this.modeLabel = getString(R.string.mode6);
		}
		
		Intent intent = this.getIntent();
		intent.putExtra("DURATION", this.timerDurationInMillis);
		intent.putExtra("MODE_LABEL", this.modeLabel);
		this.setResult(RESULT_OK, intent);
		finish();

	}
	
	@Override
	public void onBackPressed() {
		Intent intent = this.getIntent();
		intent.putExtra("DURATION", this.timerDurationInMillis);
		intent.putExtra("MODE_LABEL", (String)null);
		this.setResult(RESULT_OK, intent);
		finish();
	}

}
